package com.lambo.ws;

import com.alibaba.dubbo.config.ApplicationConfig;
import com.alibaba.dubbo.config.ReferenceConfig;
import com.alibaba.dubbo.config.RegistryConfig;
import com.alibaba.dubbo.config.utils.ReferenceConfigCache;
import com.alibaba.dubbo.rpc.service.GenericService;

/**
 * //TODO 功能介绍
 *
 * @author : ZengLinBao
 * @version : 1.0
 * @date :  2019-08-07 17:00
 **/
public class GenericServiceAppTest {

    public static void main(String[] args) throws InterruptedException {
        // 普通编码配置方式
        ApplicationConfig application = new ApplicationConfig();
        application.setName("dubbo-consumer");

        // 连接注册中心配置
        RegistryConfig registry = new RegistryConfig();
        registry.setAddress("zookeeper://127.0.0.1:2181");
        application.setRegistry(registry);
        registry.setFile("N/A");

        ReferenceConfig reference = new ReferenceConfig();
        reference.setApplication(application);
        reference.setRegistry(registry);
        reference.setGeneric("com.lambo.ws.service.HelloWorldService");
        reference.setInterface("com.lambo.ws.service.HelloWorldService");
        // 声明为泛化接口
        reference.setGeneric(true);

        GenericService helloWorldService = (GenericService) reference.get();
        System.out.println("ConsumerRunner.postConstruct :: " + helloWorldService);
        while (true) {
            try {
                String[] parameterTypes = {"java.lang.String", "java.lang.String"};
                Object[] args2 = {"lambo", "nihao too!"};
                Object result = helloWorldService.$invoke("sayHello", parameterTypes, args2);
                System.out.println("result == " + result);
            } catch (Exception e) {
                e.printStackTrace();
            }
            Thread.sleep(1000);
        }
    }
}
